package com.zhouxiaoge.utils;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;

/**
 * @author 周明阳
 * mail:gqzmy@outlook.com
 * 时间:2018-03-29 15:28
 */

public class BaseUtil {

    public static void login(String config, String username, String password) {
        Factory<SecurityManager> factory = new IniSecurityManagerFactory(config);
        SecurityManager securityManager = factory.getInstance();

        SecurityUtils.setSecurityManager(securityManager);

        Subject subject = SecurityUtils.getSubject();
        System.out.println();
        UsernamePasswordToken token = new UsernamePasswordToken(username, password);
        subject.login(token);

    }
}
